import { defineStore } from "pinia";
import { epThemeKey } from "../../index";
import { getConfig, store } from "../../utils";

export const useEpThemeStore = defineStore("pure-epTheme", {
  state: () => ({
    epThemeColor: getConfig().EpThemeColor,
    epTheme: getConfig().Theme
  }),
  getters: {
    getEpThemeColor(state) {
      return state.epThemeColor;
    },
    /** 用于mix导航模式下hamburger-svg的fill属性 */
    fill(state) {
      if (state.epTheme === "light") {
        return "#409eff";
      } else {
        return "#fff";
      }
    }
  },
  actions: {
    setEpThemeColor(newColor: string): void {
      this.epThemeColor = newColor;
    }
  },
  persist: {
    key: epThemeKey,
    storage: localStorage
  }
});

export function useEpThemeStoreHook() {
  return useEpThemeStore(store);
}
